/*
This program is submitted as part of an assignment in the
J2E
Fall Semester 2010-2011 
School of Computer Science
Interdisciplinary Center, Hertzelia, Israel 

http://www.idc.ac.il 

Exercise No.         : 2
File Name            : GameActivity.java
Names (First Last)   : Itay Sorani, Nadav Ziv, Yonathan Zarsky
Student No.          : 066530254, 039937883, 039692918
*/

package com.example;

import android.os.Bundle;
import com.example.View.GameView;
import com.example.util.UserRequestListener;

/**
 * A game activity, holds and handles the main game.
 */
public class GameActivity extends BaseActivity {

   private GameControllerProxy proxy;
   private ClientController clientController;
   private GameView view;
   
   /**
    * Called when the activity is first created.
    */
   @Override
   public void onCreate(Bundle savedInstanceState) {
	   super.onCreate(savedInstanceState);
	   setContentView(R.layout.game_screen);
	   proxy = new GameControllerProxy();
       clientController = new ClientController(proxy,this);
       view = (GameView)findViewById(R.id.gameView);
       view.setGameModel(clientController.getModels());
       view.setUserRequestListener(new UserRequestListener() {
    	   @Override
    	   public void onNewModelCreationRequest (int xTouchPosition, int yTouchPosition) {
    		   proxy.performNewModelCreationRequest(xTouchPosition,yTouchPosition);
    	   }
    	   @Override
    	   public void onGameExit() {
    		   proxy.performGameExit();
    	   }
       });
       clientController.setView(view);
       clientController.readMapFromFile(R.raw.background);
   }
   
   /*
    * Creates a new controller thread
    */
   @Override
   protected void onStart(){
	   super.onStart();
	   Thread controllerThread = new Thread (clientController);   	
	   controllerThread.start();
   }
}
